package com.base.engine.gui;

import java.util.ArrayList;

import org.lwjgl.input.Mouse;

import com.base.engine.MADEngine;
import com.base.engine.game.MADGame;
import com.base.engine.graphics.Color4f;
import com.base.engine.graphics.MADRenderer;

import static org.lwjgl.opengl.GL11.*; 

public class MADMenuScreen extends MADGamingInterface{

	public static final int WIDTH = 350 ; 
	public static final int HEIGHT = 500 ; 
	
	private ArrayList<MADButton> buttons ; 
	
	public MADMenuScreen(MADGame g, float left, float top, float width, float height) {
		super(g, left, top, width, height, "menu");
		buttons = new ArrayList<MADButton>(); 
		initMenu(); 
	}
	
	private void initMenu(){
		buttons.add(new MADButtonResumeGame(this.getGame(), getLeft()+(getWidth()-(getWidth()-40))/2,getTop()+10,
									getWidth()-40,35)); 
		buttons.add(new MADButtonExitGame(this.getGame(), getLeft()+(getWidth()-(getWidth()-40))/2, getTop()+55,
									getWidth()-40, 35)); 
		for(MADButton b: buttons)
			b.deactivate(); 
	}

	public void activate(){
		setVisible(true); 
		this.getGame().setPaused(true) ; 
		Mouse.setCursorPosition(MADEngine.WIDTH / 2, MADEngine.HEIGHT / 2); 
		for(MADButton b: buttons)
			b.setVisible(true);
	}

	public void deactivate(){
		setVisible(false); 
		for(MADButton b: buttons)
			b.setVisible(false);
		this.getGame().setPaused(false) ; 
	}
	
	
	public void render(){
		if(super.isVisible()){
			glPushMatrix();
				glLineWidth(2); 
				MADRenderer.renderRectangle_2f(MADEngine.displayVertices, new Color4f(0,0,0,0.7f), GL_QUADS); 
				MADRenderer.renderRectangle_2f(vertices, new Color4f(0.15f,0.15f,0.15f,1.0f), GL_QUADS);
				MADRenderer.renderRectangle_2f(vertices, new Color4f(0.05f,0.05f,0.05f,1.0f), GL_LINE_LOOP);
				for(MADButton b: buttons){
					b.render(); 
				}
			glPopMatrix();
		}
	}
	
	public ArrayList<MADButton> getButtons(){
		return this.buttons; 
	}
	
}
